﻿@using GraduationProject.Model
@{
    Layout = null;
    var UserModel = ViewData["UserModel"] as User;
    var SortModel = ViewData["SortModel"] as List<SortList>;
}

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <title>发表新帖 - 社区</title>
    <link href="~/Content/css/base.css" rel="stylesheet" />
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/css/global2.css" rel="stylesheet" />
    <link href="~/Content/css/global.css" rel="stylesheet" />
</head>
<body>
    <!-- 头部 -->
    <div class="fly-header layui-bg-blue">
        <div class="layui-container">
            <a class="fly-logo" href="/Home/Index">
                <img src="~/Content/layui/images/logo.png" alt="layui">
            </a>
            <ul class="layui-nav fly-nav layui-hide-xs">
                <li class="layui-nav-item">
                    <a href="/Home/MapPage"><i class="iconfont icon-jifen"></i>地图</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/Admin/AdminLogin/AdminLogin"><i class="iconfont icon-iconmingxinganli"></i>后台</a>
                </li>
                <span class="layui-nav-bar"></span>
            </ul>
            @if (UserModel != null)
            {
                <ul class="layui-nav fly-nav-user">
                    <li class="layui-nav-item">
                        <a class="fly-nav-avatar" href=""><img src="@UserModel.HeadPortrait" class="layui-nav-img">@UserModel.UserName</a>
                        <dl class="layui-nav-child">
                            <dd><a href="/Novel/InsertNovel">发表文章</a></dd>
                            <dd><a href="/UserInfo/UpDatePW">修改密码</a></dd>
                     
                            <dd><a href="/UserInfo/LoginPage">退出</a></dd>
                        </dl>
                    </li>
                </ul>
            }
            else
            {
                <ul class="layui-nav fly-nav-user">
                    <!-- 未登入的状态 -->
                    <li class="layui-nav-item">
                        <a class="iconfont icon-touxiang layui-hide-xs" href="/UserInfo/LoginPage"></a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="/UserInfo/LoginPage">登入</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="/UserInfo/RegistrationPage">注册</a>
                    </li>
                    <span class="layui-nav-bar"></span>
                </ul>
            }
        </div>
    </div><!-- 头部 end -->
    <div class="layui-container fly-marginTop">
        <div class="fly-panel" pad20="" style="padding-top: 5px;">
            <div class="layui-form layui-form-pane">
                <div class="layui-tab layui-tab-brief" lay-filter="user">
                    <ul class="layui-tab-title">
                        <li class="layui-this">发表新帖</li>
                    </ul>
                    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                        <div class="layui-tab-item layui-show">
                            <form method="post">
                                <div class="layui-row layui-col-space15 layui-form-item">
                                    <div class="layui-col-md3">
                                        <label class="layui-form-label">所在专栏</label>
                                        <div class="layui-input-block">
                                            <select lay-verify="required" name="SortType" id="SortType" lay-filter="column">
                                                @if (SortModel != null)
                                                {
                                                    foreach (var item in SortModel)
                                                    {
                                                        <option value="@item.SortID">@item.SortName</option>
                                                    }
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-col-md9">
                                        <label for="L_title" class="layui-form-label">标题</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="L_title" name="NovelTitle" required="" lay-verify="required" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                    <div class="layui-col-md12">
                                        <label for="L_title" class="layui-form-label">内容摘要</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="L_Summary" name="NovelSummary" required="" lay-verify="required" autocomplete="off" class="layui-input" />
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <div class="layui-input-block">
                                        <textarea class="layui-textarea" id="LAY_demo1" style="display: none">  把编辑器的初始内容放在这textarea即可</textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn" type="button" lay-filter="*" lay-submit>立即发布</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="fly-footer">

    </div>
    <script src="~/Content/layui/layui.js"></script>
    <script>
        layui.use(['layedit', 'jquery', 'form','element'], function () {
            var layedit = layui.layedit
                , $ = layui.jquery, form = layui.form, element = layui.element;
            layedit.set({
                uploadImage: {
                    url: '/Novel/UploadImage' //接口url
                    , type: 'post' //默认post
                }
            });
            //构建一个默认的编辑器
            var index = layedit.build('LAY_demo1');

            //编辑器外部操作
            var active = {
                content: function () {
                    alert(); //获取编辑器内容
                }
                , text: function () {
                    alert(layedit.getText(index)); //获取编辑器纯文本内容
                }
                , selection: function () {
                    alert(layedit.getSelection(index));
                }
            };
            $('.site-demo-layedit').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //自定义工具栏
            layedit.build('LAY_demo2', {
                tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
                , height: 100
            })
            //提交事件触发
            form.on('submit(*)', function (data) {
                data.field.NovelBody = layedit.getContent(index);
                //上传成功 注册用户数据
                $.ajax({
                    type: "post",
                    url: "/Novel/Insert",
                    data: data.field,
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, { icon: 1 });

                        }
                        else {
                            layer.msg(res.msg, { icon: 2 });
                        }
                    }
                });
                return false;
            });
        });
    </script>
    <span id="cnzz_stat_icon_30088308"></span>
    <ul class="layui-fixbar">
        <li class="layui-icon" lay-type="bar1" style="background-color:#009688"></li>
        <li class="layui-icon layui-fixbar-top" lay-type="top" style="background-color:#009688"></li>
    </ul>
    <div class="layui-layer-move" style="cursor: move; display: none;"></div>
</body>
</html>